//
//  YKAnimationPresentedProxy.m
//  AnchorPoint
//
//  Created by 吴高烽 on 2016/11/20.
//  Copyright © 2016年 吴高烽. All rights reserved.
//

#import "YKAnimationPresentedProxy.h"

@implementation YKAnimationPresentedProxy
//执行转场时间
- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext{
    return 0.5f;
}
//执行转场动画
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{
//    1. 获取容器view
    UIView *containerView = [transitionContext containerView];
//    2.获取目标view
    UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
//    3. 把目标View加到容器view中
    [containerView addSubview:toView];
    
//    4. 开始实现动画
    toView.transform = CGAffineTransformMakeRotation(-M_PI_2);
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        toView.transform = CGAffineTransformIdentity ;
    } completion:^(BOOL finished) {
//        转场动画结束后必须调用以下方法，不然目标view无法监听事件
        [transitionContext completeTransition:YES];
        UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
        [containerView insertSubview:fromView atIndex:0];
    }];
}
@end
